//
//  UsernameEntryViewController.m
//  Organic
//
//  Created by Mike on 1/19/15.
//  Copyright (c) 2015 Mike Amaral. All rights reserved.
//

#import "UsernameEntryViewController.h"
#import "TextFieldCell.h"
#import "MyViewController.h"
@interface UsernameEntryViewController () {
    TextFieldCell *_usernameCell;
}

@end

@implementation UsernameEntryViewController

- (instancetype)init {
    return [super initWithStyle:UITableViewStyleGrouped];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"Demo";
    UIImage *image = [UIImage imageNamed:@"7.jpg"];
    float width = self.view.frame.size.width;
    float height = (image.size.height / image.size.width) * width;
    UIImageView *gitBannerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 15, width, height)];
    [gitBannerImageView setBackgroundColor:[UIColor grayColor]];
    gitBannerImageView.contentMode = UIViewContentModeScaleAspectFit;
    gitBannerImageView.image = image;
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetMaxY(gitBannerImageView.frame) + 15)];
    [headerView addSubview:gitBannerImageView];
    
    _usernameCell = [TextFieldCell new];
    _usernameCell.textField.placeholder = @"GitHub User";
    NSArray *cells = @[_usernameCell];
    OrganicSection *usernameSection = [OrganicSection sectionWithHeaderView:headerView headerHeight:CGRectGetHeight(headerView.frame) cells:cells];
    
    __weak typeof(self) weakSelf = self;
    OrganicCell *loginButtonCell = [OrganicCell cellWithStyle:UITableViewCellStyleDefault height:100 actionBlock:^{
        NSString *enteredUsername = _usernameCell.textField.text;
        
        
            [weakSelf viewProfileForUser:enteredUsername];
    }];
    loginButtonCell.textLabel.text = @"View Profile For User";
    loginButtonCell.textLabel.textAlignment = NSTextAlignmentCenter;
    loginButtonCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    OrganicSection *loginButtonSection = [OrganicSection sectionWithCells:@[loginButtonCell]];

    self.sections = @[usernameSection, loginButtonSection];
}

- (void)viewProfileForUser:(NSString *)user {
    //GitUserProfileViewController *demoVC = [[GitUserProfileViewController alloc] initWithGitUser:user];
    MyViewController *demoVC = [[MyViewController alloc] init];
    
    NSLog(@"");
    
    [self.navigationController pushViewController:demoVC animated:YES];
}

@end

// 版权属于原作者
// http://code4app.com (cn) http://code4app.net (en)
// 发布代码于最专业的源码分享网站: Code4App.com 
